package cn.itcast.bos.service.transit.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.transit.InOutStorageInfoRepository;
import cn.itcast.bos.dao.transit.TransitInfoRepository;
import cn.itcast.bos.domain.transit.InOutStorageInfo;
import cn.itcast.bos.domain.transit.TransitInfo;
import cn.itcast.bos.service.transit.InOutStorageInfoService;
@Service
@Transactional
public class InOutStorageInfoServiceimpl implements InOutStorageInfoService {


	@Autowired
	private InOutStorageInfoRepository inOutStorageInfoRepository;
	
	@Autowired
	private TransitInfoRepository transitInfoRepository;
	 
	@Override
	public void save(InOutStorageInfo inOutStorageInfo, String transitInfoId) {
		//保存出入库对象
		inOutStorageInfoRepository.save(inOutStorageInfo);
        //关联运输流程
		  TransitInfo transitInfo = transitInfoRepository.findOne(Integer.parseInt(transitInfoId));
		// 关联出入库信息 到 运输配送对象  本项目中的运输对象和出入库是一对多的关系  一般情况都是多方关联一方 但是出入库类中没有运输对象的字段 
		  //所以用一方关联多方
			transitInfo.getInOutStorageInfos().add(inOutStorageInfo);
			System.out.println("获取的状态是"+transitInfo.getStatus());
			// 修改状态
			if (inOutStorageInfo.getOperation().equals("到达网点")) {
				transitInfo.setStatus("到达网点");
				// 更新网点地址 ，显示配送路径
				transitInfo.setOutletAddress(inOutStorageInfo.getAddress());
			}
	}


	 
	
	 
	 
	 

}
